//
//  UserCareerExpModel.m
//  CoolTennisBall
//
//  Created by Coollang on 16/9/6.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "UserCareerExpModel.h"
#import "NSString+Extension.h"

@implementation UserCareerExpModel

+ (void)requestCarceerExpListDatacompletion:(void(^)(NSArray *exps))completion {
    
    
    YFUserApi *getcarceerApi = [YFUserApi requestGetUserDataWithReqType:kUserGetCareerDataListApi];
    
    [[YFNetworkingService sharedInstance] sendRequest:getcarceerApi callback:^(BOOL success, id result, NSError *error) {
        if (success) {
            NSArray *data = getcarceerApi.responseJSONObject[@"errDesc"];
            NSMutableArray *arrM = [NSMutableArray array];
            for (NSDictionary *dict in data) {
                UserCareerExpModel *model =  [UserCareerExpModel parseCareerExpDictionary:dict];
                [arrM addObject:model];
            }
            completion(arrM.copy);
        }else {
            completion(nil);
        }
    }];
}

+ (instancetype)parseCareerExpDictionary:(NSDictionary *)dictionary {
    
    UserCareerExpModel *expModel = [[self alloc] initWithDict:dictionary];
    
    return expModel;
}

- (instancetype)initWithDict:(NSDictionary *)dict {
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

@end

@implementation UserExpSameYearModel

- (NSMutableArray<UserCareerExpModel *> *)careerArr {
    if (_careerArr == nil) {
        _careerArr = [NSMutableArray array];
    }
    return _careerArr;
}

- (CGFloat)rowHeight {
    
    if (_rowHeight > 0) {
        return _rowHeight;
    }
    
    __block CGFloat height = 0;
    
    [self.careerArr enumerateObjectsUsingBlock:^(UserCareerExpModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        CGSize textSize = [obj.Career textSizeWithtextMaxSize:CGSizeMake(kYFScreenWidth - 53, MAXFLOAT) font:[UIFont systemFontOfSize:16]];
        height += textSize.height + 16;
        if (idx == self.careerArr.count - 1) {
            height += 22;
        }
    }];
    // height：详细文本框的高度 13 间距 32 顶部距离 20:年份的高度
    _rowHeight = (height + 13 + 32 + 20);
    
    return _rowHeight;
}

@end
